home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / ANSIshellƒ / os_mac_eventchk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-29  |  1.9 KB  |  93 lines  |  [TEXT/MPCC]

  1. /* os_mac_eventchk.c */
  2.  
  3. /* 18Jan95  e  - a timer option for scheduling event checks */
  4.  
  5. #include "os_mac.h"
  6.  
  7. #if USE_EVENTCHK_TIMER
  8.  
  9. #include "os_mac_eventchk.h"
  10. #include <Timer.h>
  11. #include <stdlib.h>
  12.  
  13. extern int _atexit( void(*efun)(void) );
  14.  
  15. #ifndef mSecsBetweenEventChecks
  16. #define mSecsBetweenEventChecks 100
  17. #endif
  18.  
  19. #if GENERATINGPOWERPC
  20. #pragma options align=mac68k
  21. #endif
  22.  
  23. typedef struct tinfoRec
  24. {
  25.   TMTask TMTask;
  26.   short filler;
  27.   long *eventchk_ticks;
  28. } tinfoRec, *tinfoPtr;
  29.  
  30. #if GENERATINGPOWERPC
  31. #pragma options align=reset
  32. #endif
  33.  
  34. static tinfoRec gTimeInfo;
  35.  
  36. static TimerUPP tmt_handlerUPP = NULL;
  37.  
  38. #if powerc
  39. static pascal void tmt_handler(TMTaskPtr a1)
  40. {
  41.   *((tinfoPtr )a1)->eventchk_ticks = 1;
  42.   PrimeTime((QElemPtr )a1, mSecsBetweenEventChecks);
  43. }
  44. #else
  45. #ifndef __MWERKS__
  46. static pascal void tmt_handler(void)
  47. {
  48.   asm
  49.   {
  50.     MOVEA.L tinfoRec.eventchk_ticks(A1), A0
  51.     ADDQ.L #1, (A0)
  52.     MOVE.L A1, A0
  53.     MOVE.L #mSecsBetweenEventChecks, D0
  54.     DC.W 0xA05A ; PrimeTime
  55.   }
  56. }
  57. #else
  58. asm static pascal void tmt_handler(void)
  59. {
  60.     MOVEA.L 0x18(A1), A0 // tinfoRec.eventchk_ticks(a1)
  61.     ADDQ.L #1, (A0)
  62.     MOVEA.L A1, A0
  63.     MOVE.L #mSecsBetweenEventChecks, D0
  64.     DC.W 0xA05A // PrimeTime
  65.     RTS
  66. }
  67. #endif
  68. #endif
  69.  
  70. void cancel_eck_timer(void)
  71.   if (gTimeInfo.TMTask.tmAddr != NULL && gTimeInfo.TMTask.qType < 0 )
  72.   { RmvTime((QElemPtr )&gTimeInfo.TMTask);
  73.     gTimeInfo.TMTask.tmAddr = NULL;
  74.   }
  75. }
  76.  
  77. void init_eck_timer(void)
  78. { if (tmt_handlerUPP == NULL) tmt_handlerUPP = NewTimerProc(tmt_handler);
  79.   if (gTimeInfo.TMTask.tmAddr == NULL)
  80.   { gTimeInfo.TMTask.tmAddr = tmt_handlerUPP;
  81.     gTimeInfo.TMTask.tmWakeUp = 0;
  82.     gTimeInfo.TMTask.tmReserved = 0;
  83.     gTimeInfo.eventchk_ticks = &next_eventchk_ticks;
  84.     next_eventchk_ticks = 0;
  85.     InsTime((QElemPtr )&gTimeInfo.TMTask);
  86.     _atexit(cancel_eck_timer);
  87.     PrimeTime((QElemPtr )&gTimeInfo.TMTask, mSecsBetweenEventChecks);
  88.   }
  89. }
  90.  
  91. #endif
  92.